#ifndef UI_UPDATE_H
#define UI_UPDATE_H

#include <QSize>
#include <QWidget>
#include <QMainwindow>

#define UPDATE_UI true
#define UI_UPDATA_DEBUG false  //新增加控件时调试
#define UI_NAME_FILTER (widgetName != "centralWidget" && !widgetName.isEmpty() && !widgetName.startsWith("qt_"))//根据ui控件名字筛选条件得到ui设计界面手动添加的控件
#define WINDOW_SIZE_OFFSET 50 //窗口偏移大小 作为UI更新的阈值

#define UI_UPDATE_DEFINE    UiUpdate *ui_update;\
                            void resizeEvent(QResizeEvent *event) override\
                            {\
                                ui_update->ui_window_resize(event);\
                                QMainWindow::resizeEvent(event);  \
                            }
#define UI_UPDATE_INIT ui_update = new UiUpdate(this);

class MainWindow;
typedef class MainWindow Window;

class UiUpdate
{
private:
   typedef struct
    {
        float pos_x_rate;   //x坐标的比例
        float pos_y_rate;   //y坐标的比例
        float size_w_rate;  //宽度的比例
        float size_h_rate;  //高度的比例
    }Module_Parameters; 
    Module_Parameters *module_parameters;
    void ui_parameter_cal(QSize window_size, QWidget *widget, Module_Parameters& para);
    void ui_updata_layout(QSize newWindowSize, QWidget *widget, const Module_Parameters para);
    
    int module_number;
    Window * mainwindow;
public:
    void ui_window_resize(QResizeEvent *event);
    UiUpdate(Window* parent);
    ~UiUpdate();
    void ui_parameter_init();

};

#endif
